#include <stdio.h>

struct ListNode {
    int val;
    struct ListNode *next;
};

// 迭代
// 时间复杂度：O(n)
// 空间复杂度：O(1)
void printListIter(struct ListNode *head) {
    while (head != NULL) {
        printf("%d\n", head->val);
        head = head->next;
    }
}

// 递归
void printList(struct ListNode *head) {
    if (head == NULL) return;
    printf("%d\n", head->val);
    printList(head->next);
}

int main(void) {
    struct ListNode node2 = {3, NULL};
    struct ListNode node1 = {2, &node2};
    struct ListNode head = {1, &node1};
    printListIter(&head);
    printList(&head);
    return 0;
}
